package com.jl.security;

import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import com.jl.card.ErrorProcess;

public class Digest {
	
	static{
		Crypto.init();
	}

	/** security provider name */
	private final static String providerName = "BC";

	public static byte[] digest(String name, byte[] data, int offset, int len) {
		MessageDigest md = null;
		name = name.trim().toUpperCase();
		try {
			md = MessageDigest.getInstance(name, providerName);
		} catch (GeneralSecurityException e) {
			ErrorProcess
					.throwRuntimeException("Specified mechanism not supported!");
		}
		md.update(data, offset, len);
		return md.digest();
	}

}
